/**
* 作者: hwp
* 日期: 2025-05-16 16:06:10
* 备注: 联盟已解锁地标装饰
*/
package com.motu.monstercity.server.game.userdata;

import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UnionUnlockDecorationModel extends BaseModel implements Model {
	public static final String LISTKEY = "union_id";
	public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
	public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
	public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

	protected long id; // 装饰id
	protected long unionId; // 联盟ID
	protected long userId; // 解锁人
	protected long unlockTime; // 解锁时间
	protected int level; // 等级

	public void reset() {
	}

	protected String getKey() {
		return "UnionUnlockDecoration." + id;
	}

	protected String getListKey() {
		return "UnionUnlockDecoration." + unionId;
	}

	protected String getListItemKey() {
		return id + "";
	}

	public void doCreate() {
		setTableId();
		insert();
	}

	public void setTableId() {
		putId(incrTableId("union_unlock_decoration"));
	}

	public JsonObject insert() {
		return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	public void delete() {
		super.delete(getKey(), id, UPDATE_DB_TYPE, 0, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	/**
	* 根据入库类型更新
	*/
	public JsonObject update() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	/**
	* 实时入队列
	*/
	public JsonObject updateQueueNow() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	public JsonObject getAllObj(){
		JsonObject obj = new JsonObject();
		obj.put("id", id); // 装饰id
		obj.put("unionId", unionId); // 联盟ID
		obj.put("userId", userId); // 解锁人
		obj.put("unlockTime", unlockTime); // 解锁时间
		obj.put("level", level); // 等级
		return obj;
	}

	public long getId() {
		return id;
	}

	public void putId(long id) {
		if (this.id != id) {
			this.id = id;
			updateRedisHashField(getKey(), "id", this.id);
		}
	}

	public void addId(long value) {
		this.id += value;
		updateRedisHashField(getKey(), "id", this.id);
	}

	public long getUnionId() {
		return unionId;
	}

	public void putUnionId(long unionId) {
		if (this.unionId != unionId) {
			this.unionId = unionId;
			updateRedisHashField(getKey(), "unionId", this.unionId);
		}
	}

	public void addUnionId(long value) {
		this.unionId += value;
		updateRedisHashField(getKey(), "unionId", this.unionId);
	}

	public long getUserId() {
		return userId;
	}

	public void putUserId(long userId) {
		if (this.userId != userId) {
			this.userId = userId;
			updateRedisHashField(getKey(), "userId", this.userId);
		}
	}

	public void addUserId(long value) {
		this.userId += value;
		updateRedisHashField(getKey(), "userId", this.userId);
	}

	public long getUnlockTime() {
		return unlockTime;
	}

	public void putUnlockTime(long unlockTime) {
		if (this.unlockTime != unlockTime) {
			this.unlockTime = unlockTime;
			updateRedisHashField(getKey(), "unlockTime", this.unlockTime);
		}
	}

	public void addUnlockTime(long value) {
		this.unlockTime += value;
		updateRedisHashField(getKey(), "unlockTime", this.unlockTime);
	}

	public int getLevel() {
		return level;
	}

	public void putLevel(int level) {
		if (this.level != level) {
			this.level = level;
			updateRedisHashField(getKey(), "level", this.level);
		}
	}

	public void addLevel(int value) {
		this.level += value;
		updateRedisHashField(getKey(), "level", this.level);
	}

}